#include "ui_widget/widget.h"

#include <QApplication>
#include <QDebug>
#include "log/TSpdlog.h"
#include "helper/DirHelper.h"
#include <QQmlApplicationEngine>
#define USE_QML

#include "Application.h"

int main(int argc, char *argv[])
{
    if (!Application::init()) {
        return -1;
    }

    if (Application::setSingleApp("QtApp.lock")) {
        return -1;
    }

    Application app(argc, argv);
    
    qDebug() << DirHelper::getInstance()->getCurrentDirPath();
    if (!app.addTranslation()) {
        TSpdlog::getInstance()->otherError("translator error");
    }
//    int a = 0;
//    qDebug() << 1/a;

#ifdef USE_QML
    /* 如果不使用qml则移除pro文件、头文件等，这样可以减少dll依赖 */
    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);
#endif

    Widget w;
    w.show();
    return app.exec();
}
